package com.lebang.model.back;

import com.lebang.common.Util;
import com.lebangweb.common.UUIDUtil;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;

/**
 * @Author: hwq
 * @Date: 2020/5/8 17:08
 * @Version 1.0
 */
@Data
@Document("imei_register")
public class ImeiRegister {

    @Field
    private String appid;
    @Field
    private String appStore;
    @Field
    private String brand;
    @Id
    private String imei;
    @Field
    private String macAddr;
    @Field
    private String os;
    @Field
    private String osv;
    @Field
    private String version;
    @Field
    private String ipAddr;
    @Field
    private String ua;
    @Field
    private String appSecret;
    private String oldImei;
    private String osVersion;
    private String oaid;
    private String android_id;
    private LocalDateTime createDateTime;


    public ImeiRegister() {
    }

    public ImeiRegister(HttpServletRequest request) {
        this.appid = request.getHeader("appid") == null ? "xianyu" : request.getHeader("appid");
        this.appStore = request.getHeader("appStore");
        this.version = request.getHeader("version");
        this.imei = request.getHeader("imei")== null ? "NoneImei:"+ UUIDUtil.NS() : request.getHeader("imei");
        this.oldImei=request.getHeader("imei");
        this.brand = request.getHeader("brand");
        this.os = request.getHeader("os");
        this.osv = request.getHeader("osv");
        this.macAddr = request.getHeader("macAddr");
        this.ipAddr = Util.getIpAddress(request);
        this.ua = request.getHeader("ua") == null ? "" : request.getHeader("ua");
        this.appSecret = request.getHeader("appSecret") == null ? "" : request.getHeader("appSecret");
        this.osVersion=request.getHeader("os_version")==null?"": request.getHeader("os_version");
        this.oaid = request.getHeader("oaid") == null ? "" : request.getHeader("oaid");
        this.android_id = request.getHeader("android_id") == null ? "" : request.getHeader("android_id");
        this.createDateTime=LocalDateTime.now();
    }
}
